/*
 * Copyright 2016 Stuart Kent
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.
 *
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package com.example.mybugshaker.flow.email;

import ohos.agp.window.service.Display;
import ohos.agp.window.service.DisplayAttributes;
import ohos.agp.window.service.DisplayManager;
import ohos.app.Context;
import ohos.system.DeviceInfo;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;

public final class Device {

    @NotNull
    private static String getDensityBucketString(@NotNull final DisplayAttributes displayAttributes) {
        switch (displayAttributes.densityDpi) {
            case DisplayAttributes.LOW_DENSITY:
                return "ldpi";
            case DisplayAttributes.MEDIUM_DENSITY:
                return "mdpi";
            case DisplayAttributes.HIGH_DENSITY:
                return "hdpi";
            default:
                return "Unknown";
        }
    }

    @NotNull
    private final String resolution;

    @NotNull
    private final String actualDensity;

    @NotNull
    private final String densityBucket;

    public Device(@NotNull final Context context) {
        Optional<Display> display = DisplayManager.getInstance().getDefaultDisplay(context);
        DisplayAttributes displayAttributes = display.get().getAttributes();
        resolution = displayAttributes.yDpi + "x" + displayAttributes.xDpi;
        actualDensity = displayAttributes.densityDpi + "dpi";
        densityBucket = getDensityBucketString(displayAttributes);
    }

    @NotNull
    public String getManufacturer() {
        // 获取开发商
        return DeviceInfo.getName();
    }

    @NotNull
    public String getModel() {
        // 获取手机Model
        return DeviceInfo.getModel();
    }

    @NotNull
    public String getResolution() {
        return resolution;
    }

    @NotNull
    public String getActualDensity() {
        return actualDensity;
    }

    @NotNull
    public String getDensityBucket() {
        return densityBucket;
    }
}
